package com.goudan.demo.controller;

import com.goudan.demo.entity.valid.ValidationParam;
import com.goudan.demo.util.ValidGroup;
import com.goudan.demo.util.ValidationUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;

@Slf4j
@RestController
public class ValidaController {

    /**
     * 不分组校验
     * http://127.0.0.1:8089/valida?username=%22%E5%BC%A0%E4%B8%89%22&phone=12345678&idCard=%22210782199002281217%22
     */
    @RequestMapping("/valida")
    public String valida(ValidationParam req) {
        log.info("参数校验，入参为：{}", req);
        ValidationUtil.validate(req);
        return "成功";
    }

    /**
     * 分组校验
     */
    @RequestMapping("/validaGroup")
    public String validaGroup(ValidationParam req) {
        log.info("参数校验，入参为：{}", req);
        ValidationUtil.validate(req, ValidGroup.Update.class, Default.class);
        return "成功";
    }
}
